package Response; /**
 * @author 李某
 * * @date 2021/11/19
 * *物有本末，事有终始。知其先后者，则近道矣！
 * *荷花开满池塘的前一天还是半塘荷花半塘云。
 */

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;

@WebServlet("/DataPut")
public class DataPut extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("测试输出DoGet");

        response.setCharacterEncoding("utf-8");
        // 1.requese 解析请求参数 name=2332905549&pwd=010321
        // 获取name参数
        String s = request.getParameter("name"); // 获取了name
        System.out.println(s);
        String pwd = request.getParameter("pwd"); // 获取了name
        System.out.println(pwd);
        String hobby = request.getParameter("hobby"); // 获取了name
        System.out.println(hobby);

        response.getWriter().write("<h1>" + s + "</h1>");
        response.getWriter().write("<h2>" + pwd + "</h2>");
        response.getWriter().write("<h3>" + hobby + "</h3>");

        String[] hobbys = request.getParameterValues("hobby");
        System.out.println(Arrays.toString(hobbys));


//        for (String hobby1 : hobbys) {
//            response.getWriter().write("<h3>" + hobby1 + "</h3>");
//        }

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        System.out.println("测试输出DoPost");
        doGet(request, response);
    }

}
